/*
 * @Author: Jan-superman
 * @Date: 2018-09-27 20:38:14
 * @Last Modified by: Jan-superman
 * @Last Modified time: 2018-11-07 23:17:13
 */

import React, { PureComponent } from 'react';
import NProgress from 'nprogress';
import withRouter from 'umi/withRouter';
import { connect } from 'dva';
import '@/layouts/nprogress.less';

NProgress.configure({ showSpinner: false });

class BasicLayout extends PureComponent {
	render() {
		const { children, location, loading } = this.props;

		let currHref = '';
		console.log('loading.global', loading.global);
		const { href } = window.location; // 浏览器地址栏中地址
		if (currHref !== href) {
			// currHref 和 href 不一致时说明进行了页面跳转
			NProgress.start(); // 页面开始加载时调用 start 方法
			if (!loading.global) {
				console.log('loading.global', loading.global);
				// loading.global 为 false 时表示加载完毕
				NProgress.done(); // 页面请求完毕时调用 done 方法
				currHref = href; // 将新页面的 href 值赋值给 currHref
			}
		}
		return <div>{children}</div>;
	}
}

export default withRouter(connect(({ app, loading }) => ({ app, loading }))(BasicLayout));
